home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
FULLPATH.C
< prev
next >
Wrap
Text File
|
1992-05-30
|
3KB
|
107 lines
/********************************/
/* File: FullPathName.c */
/* */
/* Given the name and working */
/* directory of a file, walk the*/
/* directory tree to determine */
/* what the full pathname of the*/
/* directory is... */
/* */
/* Paramters: */
/* param0 = file name num */
/* param1 = directory id */
/* */
/* Out: */
/* full pathname of the working */
/* directory */
/* ---------------------------- */
/* Once again, I am indepbted to*/
/* Steve Maller of Apple */
/* Computer Inc for illuminating*/
/* this oft too dark realm of */
/* the toolbox. */
/********************************/
#include <MacTypes.h>
#include <OSUtil.h>
#include <MemoryMgr.h>
#include <FileMgr.h>
#include <ResourceMgr.h>
#include <pascal.h>
#include <strings.h>
#include <hfs.h>
#include "HyperXCmd.h"
#include "HyperUtils.h"
#define nil 0L
char colon[2] = "\p:";
pascal void main( paramPtr )
XCmdBlockPtr paramPtr;
{
Str31 str,fName;
short wdid;
WDPBRec theWDPB;
CInfoPBRec theCPB;
HParamBlockRec theHPB;
char fullPath[256];
char part_Name[256]; /*** used in HPB ***/
char vol_Name[256];
OSErr err;
colon[0] = 1;
colon[1] = ':';
vol_Name[0] = '\0';
part_Name[0]= '\0';
/*** empty is the default answer ***/
paramPtr->returnValue = 0L;
HLock( paramPtr->params[0] );
ZeroToPas( paramPtr, *(paramPtr->params[0]), &fName );
HUnlock( paramPtr->params[0] );
/*** convert the wdid to a usable form ***/
HLock( paramPtr->params[1] );
ZeroToPas( paramPtr, *(paramPtr->params[1]), &str );
HUnlock( paramPtr->params[1] );
wdid = StrToNum( paramPtr, &str );
/*** First, we appeal to GetVInfo to get ***/
/*** the volume name that the file lives on ***/
part_Name[0] = '\0';
theHPB.volumeParam.ioNamePtr = (StringPtr)vol_Name;
theHPB.volumeParam.ioVRefNum = (short)wdid;
theHPB.volumeParam.ioVolIndex = 0;
if(PBHGetVInfo( &theHPB, 0) != noErr )
return;
/*** Next, use the working directory info ***/
/*** to walk the directory tree backwards ***/
/*** to the root directory ***/
theWDPB.ioNamePtr = (StringPtr)part_Name;
theWDPB.ioVRefNum = wdid;
theWDPB.ioWDProcID = 0;
theWDPB.ioWDIndex = 0;
if( PBGetWDInfo( &theWDPB, 0) != noErr )
return;
fullPath[0] = '\0';
theCPB.dirInfo.ioFDirIndex = -1;
theCPB.dirInfo.ioVRefNum = theHPB.volumeParam.ioVRefNum;
ClimbTree( theWDPB.ioWDDirID,
(CInfoPBPtr)&theCPB,
(StringPtr)fullPath );
/*** Climbing the tree yields the names of ***/
/*** all the folders which we still need to ***/
/*** add the file's name to. ***/
Concat( (char *)fullPath, (char *)&fName );
paramPtr->returnValue = PasToZero( paramPtr, fullPath );
}